package dao

import (
	"context"
	"math/rand"
	"time"
	"user_srv/global"
)

func SetCode(key string) string {

	code := rand.Intn(9000) + 1000
	result, err := global.RedisClient.Set(context.Background(), key, code, 1*time.Minute).Result()
	if err != nil {
		return ""
	}
	return result
}

func GetCode(key string) string {

	result, err := global.RedisClient.Get(context.Background(), key).Result()
	if err != nil {
		return ""
	}
	return result
}
